/* SPDX-License-Identifier: GPL-2.0-only */
/* Copyright (c) 2011-2016, 2018, 2020, The Linux Foundation. All rights reserved.
 */
#ifndef MSM_ACTUATOR_H
#define MSM_ACTUATOR_H

#include <linux/i2c.h>
#include <linux/gpio.h>
#include <soc/qcom/camera2.h>
#include <media/v4l2-subdev.h>
#include <media/msmb_camera.h>
#include "msm_camera_i2c.h"
#include "msm_camera_dt_util.h"
#include "msm_camera_io_util.h"


#define DEFINE_MSM_MUTEX(mutexname) \
	static struct mutex mutexname = __MUTEX_INITIALIZER(mutexname)

#define	MSM_ACTUATOR_MAX_VREGS (10)
#define	ACTUATOR_MAX_POLL_COUNT 10

struct msm_actuator_ctrl_t;

enum msm_actuator_state_t {
	ACT_ENABLE_STATE,
	ACT_OPS_ACTIVE,
	ACT_OPS_INACTIVE,
	ACT_DISABLE_STATE,
};

struct msm_actuator_func_tbl {
	int32_t (*actuator_init_step_table)(struct msm_actuator_ctrl_t *a_ctrl,
		struct msm_actuator_set_info_t *set_info);
	int32_t (*actuator_init_focus)(struct msm_actuator_ctrl_t *a_ctrl,
		uint16_t size, struct reg_settings_t *settings);
	int32_t (*actuator_set_default_focus)(
			struct msm_actuator_ctrl_t *a_ctrl,
			struct msm_actuator_move_params_t *move_params);
	int32_t (*actuator_move_focus)(struct msm_actuator_ctrl_t *a_ctrl,
			struct msm_actuator_move_params_t *move_params);
	void (*actuator_parse_i2c_params)(
			struct msm_actuator_ctrl_t *a_ctrl,
			int16_t next_lens_position, uint32_t hw_params,
			uint16_t delay);
	void (*actuator_write_focus)(struct msm_actuator_ctrl_t *a_ctrl,
			uint16_t curr_lens_pos,
			struct damping_params_t *damping_params,
			int8_t sign_direction,
			int16_t code_boundary);
	int32_t (*actuator_set_position)(struct msm_actuator_ctrl_t *a_ctrl,
		struct msm_actuator_set_position_t *set_pos);
	int32_t (*actuator_park_lens)(struct msm_actuator_ctrl_t *a_ctrl);
};

struct msm_actuator {
	enum actuator_type act_type;
	struct msm_actuator_func_tbl func_tbl;
};

struct msm_actuator_vreg {
	struct camera_vreg_t *cam_vreg;
	void *data[MSM_ACTUATOR_MAX_VREGS];
	int num_vreg;
};

#ifdef CONFIG_MACH_MI
struct msm_actuator_board_info {
	char actuator_name[NAME_SIZE_MAX];
	uint32_t i2c_slaveaddr;
	struct msm_actuator_opcode opcode;
};
#endif

struct msm_actuator_ctrl_t {
	struct i2c_driver *i2c_driver;
	struct platform_driver *pdriver;
	struct platform_device *pdev;
	struct msm_camera_i2c_client i2c_client;
	enum msm_camera_device_type_t act_device_type;
	struct msm_sd_subdev msm_sd;
	enum af_camera_name cam_name;
	struct mutex *actuator_mutex;
	struct msm_actuator_func_tbl *func_tbl;
	enum msm_camera_i2c_data_type i2c_data_type;
	struct v4l2_subdev sdev;
	struct v4l2_subdev_ops *act_v4l2_subdev_ops;

	int16_t curr_step_pos;
	uint16_t curr_region_index;
	uint16_t *step_position_table;
	struct region_params_t region_params[MAX_ACTUATOR_REGION];
	uint16_t reg_tbl_size;
	struct msm_actuator_reg_params_t reg_tbl[MAX_ACTUATOR_REG_TBL_SIZE];
	uint16_t region_size;
	void *user_data;
	uint32_t total_steps;
	uint16_t pwd_step;
	uint16_t initial_code;
	struct msm_camera_i2c_reg_array *i2c_reg_tbl;
	uint16_t i2c_tbl_index;
	enum cci_i2c_master_t cci_master;
	uint32_t subdev_id;
	enum msm_actuator_state_t actuator_state;
	struct msm_actuator_vreg vreg_cfg;
	struct park_lens_data_t park_lens;
	uint32_t max_code_size;
	struct msm_camera_gpio_conf *gconf;
	struct msm_pinctrl_info pinctrl_info;
	uint8_t cam_pinctrl_status;
#ifdef CONFIG_MACH_MI
	struct msm_actuator_board_info *aboard_info;
	struct workqueue_struct *actuator_work_queue;
	struct work_struct actuator_work;
#endif
};

#endif
